package org.dawnframework.context.annotation;

import org.dawnframework.beans.factory.config.BeanDefinitionHolder;
import org.dawnframework.beans.factory.support.BeanDefinitionReaderUtils;
import org.dawnframework.beans.factory.support.BeanDefinitionRegistry;
import org.dawnframework.beans.factory.support.BeanNameDefinition;
import org.dawnframework.beans.factory.support.ScanRegisterBeanNameDefintion;

/**
 * dwan 容器读取器
 */
public  class AnnotatedBeanDefinitionReader implements  BeanDefinitionReader {


    private final BeanDefinitionRegistry registry;

    private final BeanNameDefinition beanNameDefinition = new ScanRegisterBeanNameDefintion();

    public AnnotatedBeanDefinitionReader(BeanDefinitionRegistry registry){
        this.registry = registry;

    }



    @Override
    public void register(Class<?>... componentClasses) {
        for (Class<?> componentClass : componentClasses) {
            doRegisterBean(componentClass);
        }
    }


    public void doRegisterBean(Class<?> componentClass){
        AbstractBeanDeinition abd = new RootBeanDefinition(componentClass);
        ScopeMetadata scopeMetadata = new ScopeMetadata();
        abd.setScopeName(scopeMetadata.getScopeName());
        String beanName = beanNameDefinition.getBeanName(componentClass);
        BeanDefinitionHolder beanDefinitionHolder = new BeanDefinitionHolder(abd,beanName);
        BeanDefinitionReaderUtils.registerBeanDefinition(beanDefinitionHolder, this.registry);
        System.out.println("bena register succ");
    }






}
